/*
 * Payload.cpp
 *
 *  Created on: 25.06.2011
 *      Author: mario
 */

#include "Payload.h"
#include <string.h> // memcpy

// constructor
Payload_Data::Payload_Data(uint64_t capacity)
{
  this->capacity = capacity;
  this->size = capacity; //TODO oder soll hier size = 0 hin..?
  payload = new byte[capacity];
}

//Payload_Data::Payload_Data(byte* data, int len)
//{
//  this->capacity = len;
//  this->size = len;
//  payload = data;
//
//}

// copy constructor
Payload_Data::Payload_Data(Payload_Data &other)
{
  capacity = other.size;
  size = other.size;
  payload = new byte[capacity];

  memcpy(payload, other.payload, size);
}

Payload_Data::~Payload_Data()
{
  if ( payload )
    delete[] payload;
}


int Payload_Data::get_size()
{
  return size;
}

// TODO: ggf exception, wenn size > capacity
void Payload_Data::set_size(uint64_t size)
{
  if ( size <= capacity )
    this->size = size;
}

string Payload_Data::get_key()
{
  return key;
}

void Payload_Data::set_key(string key)
{
  this->key = key;
}

uint64_t Payload_Data::get_postion()
{
    return position;
}

void Payload_Data::set_position(uint64_t pos)
{
    position = pos;
}



/** get the data **/
byte* Payload_Data::raw_pointer()
{
  return payload;
}

byte* Payload_Data::return_copy()
{
  byte* ret = new byte[size];

  memcpy(ret, payload, size);

  return ret;
}


bool Payload_Data::operator!()
{
  return size == 0;
}
